package com.zhongke.cotrun.common.handler;

import com.google.common.base.Joiner;
import com.zhongke.cotrun.model.pojo.LongSet;
import org.apache.commons.collections.CollectionUtils;

public class LongSetHandler extends BasicTypeHandler<LongSet> {

    @Override
    protected LongSet fromString(String set) {
        String[] sets = set.split(",");
        LongSet longSet = new LongSet();
        if (sets.length == 0) {
            return longSet;
        }
        for (String s : sets) {
            longSet.add(Long.valueOf(s));
        }
        return longSet;
    }

    @Override
    protected String toString(LongSet set) {
        if (CollectionUtils.isEmpty(set)) {
            return "";
        }
        return Joiner.on(",").join(set);
    }
}
